//
//  LevelDBViewController.m
//  myDemo2
//
//  Created by wuxueying on 14-4-18.
//
//

#import "LevelDBViewController.h"
//#import <Objective-LevelDB/LevelDB.h>
//#import "LDBSnapshot.h"
//#import "LDBWriteBatch.h"

@interface LevelDBViewController ()
{
//    LevelDB *ldb;
//    NSString *text;
}
@property (weak, nonatomic) IBOutlet UITextView *textView;
@property (weak, nonatomic) IBOutlet UITextField *key;
@property (weak, nonatomic) IBOutlet UITextField *value;
@end
@implementation LevelDBViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
//    ldb = [LevelDB databaseInLibraryWithName:@"test.ldb"];
//    
//    [ldb setObject:@"rain" forKey:@"name"];
//    
//    [ldb setObject:@{@"1" : @"film", @"2" : @"video"} forKey:@"hobbit"];
//    [self reloadTextView];
    
//    [ldb enumerateKeysAndObjectsUsingBlock:^(LevelDBKey *key, id value, BOOL *stop) {
//        NSString *keyString = NSStringFromLevelDBKey(key);
//        NSLog(@"%@",keyString);
//    }];

//    [ldb enumerateKeysAndObjectsBackward:TRUE
//                                  lazily:TRUE
//                           startingAtKey:nil
//                     filteredByPredicate:nil
//                               andPrefix:nil
//                              usingBlock:^(LevelDBKey *key, void(^valueGetter)(void), BOOL *stop) {
//                                  NSString *keyString = NSStringFromLevelDBKey(key);
//                                  NSLog(@"%@",keyString);
//                                  NSLog(@"%@", [ldb objectForKey:keyString]);
//                              }];
//
//    LDBSnapshot *snap = [ldb newSnapshot];
//    [ldb removeObjectForKey:@"string_test"];
//    NSLog(@"String Value: %@", [snap objectForKey:@"string_test"]);
//    NSLog(@"Dictionary Value: %@", [ldb objectForKey:@"dict_test"]);
//
//    LDBWritebatch *wb = [ldb newWritebatch];
//    [wb setObject:@{ @"foo" : @"bar" } forKey: @"another_test"];
//    [wb removeObjectForKey:@"dict_test"];
//    [wb apply];
}
- (IBAction)add:(id)sender {
//    [ldb setObject:_value.text forKey:_key.text];
//    [self reloadTextView];
}
- (IBAction)remove:(id)sender {
//    [ldb removeObjectForKey:_key.text];
//    [self reloadTextView];
}

//- (void)reloadTextView {
//    text = @"";
//    [ldb enumerateKeysAndObjectsUsingBlock:^(LevelDBKey *key, id value, BOOL *stop) {
//        NSString *keyString = NSStringFromLevelDBKey(key);
//        NSString *valueString = [ldb objectForKey:keyString];
//        text = [NSString stringWithFormat:@"%@%@--->%@\n",text,keyString,valueString];
//        _textView.text = text;
//    }];
//}

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
    [self.view endEditing:YES];
}
@end
